import './App.scss'
import { Router, Route, Switch, Redirect } from 'react-router-dom'
// import Layout from './pages/Layout/Layout'
import Login from '@/pages/Login/Login'
import Layout from '@/pages/Layout/Layout'
import ProfileEdit from '@/pages/Profile/Edit'
import PrivateRoute from './components/PrivateRoute'
import history from './utils/history'
import { hasToken } from './utils/storage'
import Chat from './pages/Profile/Chat/Chat'
import Article from './pages/Article/Article'
import Seacrch from './pages/Search/Seacrch'
import Result from './pages/Search/Result/Result'
function App () {
  return (
    <div className="app">
      <Router history={history}>
        <Switch>
          <Redirect exact from="/" to="/home" />

          {/* <Route exact path="/" render={()=><Redirect to="/home"/>} /> */}

          <Route
            path="/login"
            render={() => {
              if (hasToken()) {
                return <Redirect to="/home" />
              } else {
                return <Login />
              }
            }}
          />
          <Route path="/home" component={Layout} />

          <PrivateRoute path="/profile/edit">
            <ProfileEdit />
          </PrivateRoute>
          <PrivateRoute path="/chat">
            <Chat />
          </PrivateRoute>
          {/* 搜索 */}
          <Route exact path='/search'>
            <Seacrch/>
          </Route>
          <Route path='/article/:id'>
            <Article />
          </Route>
          <Route path='/search/result'>
            <Result></Result>
          </Route>
        </Switch>
      </Router>
    </div>
  )
}

export default App
